<template>
	<view class="home" >
		<!-- 轮播图区域 -->
		<swiper indicator-dots circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav-item" v-for="(item, index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<view>{{item.title}}</view>
			</view>
		</view>
		<!-- 推荐商品区域 -->
		<view class="hot-goods">
			<view class="title">推荐商品</view>
			<goods-list :goods="goods" @goGoodsDetail="goGoodsDetail"></goods-list>
		</view>
	</view>
</template>

<script>
	import GoodsList from '../../components/goodsList/GoodsList.vue'
	export default {
		data() {
			return {
				swipers:[],
				goods: [],
				navs: [
					{
						icon: 'iconfont icon-ziyuan',
						title: '超市',
						path: '/pages/goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '联系我们',
						path: '/pages/contact/contact'
					},
					{
						icon: 'iconfont icon-tupian',
						title: '社区图片',
						path: '/pages/pics/pics'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '视频',
						path: '/pages/video/video'
					}
				],
					
			}
		},
		components: {
			GoodsList
		},
		created() {
			this.getSwipers()
			this.getHotGoodsList()
		},
		methods: {
			// 获取轮播图的数据
			async getSwipers() {
				// uni.request({
				// 	"url": 'http://localhost:8080/static/api/getlunbo.json',
				// 	success: (res) => {
				// 		console.log(res)
				// 		if(res.data.status !== 0) {
				// 			return uni.showToast({
				// 				title: "获取数据失败"
				// 			})
				// 		}
						
				// 		this.swipers = res.data.message
				// 	}
				// })
				const res = await this.$myRequest({
					url: 'getlunbo.json'
				})
				this.swipers = res.data.message
				console.log(this.swipers)
			},
			// 获取热门商品列表
			async getHotGoodsList() {
				const res = await this.$myRequest({
					url :'getHotGoods.json'
				})
				this.goods = res.data.message.goods
			},
			// 导航跳转函数
			navItemClick(path) {
				// console.log(path)
				uni.navigateTo({
					url: path
				})
			},
			// 跳转到商品详情页面
			goGoodsDetail(id) {
				uni.navigateTo({
					url:"/pages/goodsDetail/GoodsDetail?id=" + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.nav {
			display: flex;
			padding: 10rpx 0;
			.nav-item {
				flex: 1;
				text-align: center;
				view.iconfont {
					width: 120rpx;
					height: 120rpx;
					background-color: $shop-color;
					border-radius: 50%;
					margin: 10px auto;
					line-height: 120rpx;
					color: #fff;
					font-size: 50rpx;
				}
				text {
					font-size: 30rpx;
				}
			}
		}
		.hot-goods {
			background-color: #eee;
			overflow: hidden;
			padding-top: 10rpx;
			.title {
				height: 100rpx;
				line-height: 100rpx;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20rpx;
				background-color: #fff;
				margin: 10rpx 0;
				font-weight: 600;
			}
			
		}
		
	}
</style>
